<template>
  <div class="common-page">
    <SearchForm
      :search-list="searchList"
      :search-params="searchParams"
      @search="onSearch"
      @reset="onReset"
    />
    <el-form>
      <el-form-item>
    
          <div
          class="f-r a-c j-e"
        >
              <el-button type="primary" @click="onExport" style="margin-right: 15px">模版导出</el-button>
              <el-upload
              action="#"
            style="width: 56px"
              :show-file-list="false"
              :before-upload="beforeUpload"
          >
            <el-button type="primary">导入</el-button>
          </el-upload>
          <el-button type="primary" style="margin-left: 15px" @click="onAdd">添加</el-button>
        </div>
      </el-form-item>
    </el-form>
    <div class="table-box">
      <el-table
        v-loading="loading"
        height="100%"

        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >

        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="操作" fixed="right" width="260px">
          <template slot-scope="scope">
            <el-button type="primary" @click="onRead(scope.row)">查看详情</el-button>
            <el-button type="primary" @click="onEdit(scope.row)">编辑</el-button>
            <el-button type="danger" @click="onDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <Add ref="addFormRef" @get-page="onSearch" />
    <Detail ref="detailRef" />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import Add from './add'
import Detail from './detail'
import {exportFile, http, importFile} from '@/api'
import {getName} from "@/dict";
import download from "js-file-download";
export default {
  name: 'Index',
  components: {
    Add,
    Detail
  },
  mixins: [crud],
  data() {
    return {
      request: http.professor,
      searchList: [
        {
          key: 'departType',
          name: 'select',
          label: '单位',
          options: []
        },
        {
          key: 'expertType',
          name: 'select',
          label: '专家类型',
          options: [
            { value: '1', name: '社会专家' },
            { value: '2', name: '职能科室专家' },
            { value: '3', name: '建设单位' }
          ]
        },
        {
          key: 'expertName',
          name: 'input',
          label: '专家名称'
        }
      ],
      searchParams: {
        expertType: '',
        departType: '',
        expertName: ''
      },
      columns: [
        { prop: 'expertName', label: '专家名称' },
        { prop: 'departTypeName', label: '单位' },
        { prop: 'industryName', label: '行业' },
        { prop: 'industryExpertise', label: '专业特长' }
      ],
      tableData: [

      ]
    }
  },
    created() {
        this.searchList[0].options = this.$store.getters.deptList
    },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.departTypeName = getName(el.departType, this.searchList[0].options)
      })
    },
    onRead(item) {
      this.$refs.detailRef.open(item)
    },
    beforeUpload(file) {
      importFile('/ExpertWarehouse/inExpertWarehouse', file).then(res => {
        this.onSearch()
      })
    },
      onExport() {
        window.open(baseUrl + '/ExpertWarehouse/outExpertMoban', '_blank')
        //   exportFile('/ExpertWarehouse/outExpertMoban').then(res => {
        //       console.log(res)
        //       this.$message.success(res.msg)
        //       this.loading = false
        //       download(res, '专家智库.xls')
        //   }).catch(() => {
        //       this.$message.error('导出失败')
        //       this.loading = false
        //   })
      }
  }
}
</script>

<style scoped lang="scss">
</style>
